home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / parodius.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  14KB  |  445 lines

  1. /***************************************************************************
  2.  
  3. Parodius (Konami GX955) (c) 1990 Konami
  4.  
  5. driver by Nicola Salmoria
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11. #include "cpu/konami/konami.h" /* for the callback and the firq irq definition */
  12. #include "vidhrdw/konamiic.h"
  13.  
  14. /* prototypes */
  15. static void parodius_init_machine( void );
  16. static void parodius_banking( int lines );
  17. int parodius_vh_start( void );
  18. void parodius_vh_stop( void );
  19. void parodius_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  20.  
  21. static int videobank;
  22. static unsigned char *ram;
  23.  
  24. static int parodius_interrupt(void)
  25. {
  26.     if (K052109_is_IRQ_enabled()) return interrupt();
  27.     else return ignore_interrupt();
  28. }
  29.  
  30. static READ_HANDLER( bankedram_r )
  31. {
  32.     if (videobank & 0x01)
  33.     {
  34.         if (videobank & 0x04)
  35.             return paletteram_r(offset + 0x0800);
  36.         else
  37.             return paletteram_r(offset);
  38.     }
  39.     else
  40.         return ram[offset];
  41. }
  42.  
  43. static WRITE_HANDLER( bankedram_w )
  44. {
  45.     if (videobank & 0x01)
  46.     {
  47.         if (videobank & 0x04)
  48.             paletteram_xBBBBBGGGGGRRRRR_swap_w(offset + 0x0800,data);
  49.         else
  50.             paletteram_xBBBBBGGGGGRRRRR_swap_w(offset,data);
  51.     }
  52.     else
  53.         ram[offset] = data;
  54. }
  55.  
  56. static READ_HANDLER( parodius_052109_053245_r )
  57. {
  58.     if (videobank & 0x02)
  59.         return K053245_r(offset);
  60.     else
  61.         return K052109_r(offset);
  62. }
  63.  
  64. static WRITE_HANDLER( parodius_052109_053245_w )
  65. {
  66.     if (videobank & 0x02)
  67.         K053245_w(offset,data);
  68.     else
  69.         K052109_w(offset,data);
  70. }
  71.  
  72. static WRITE_HANDLER( parodius_videobank_w )
  73. {
  74.     if (videobank & 0xf8) logerror("%04x: videobank = %02x\n",cpu_get_pc(),data);
  75.  
  76.     /* bit 0 = select palette or work RAM at 0000-07ff */
  77.     /* bit 1 = select 052109 or 053245 at 2000-27ff */
  78.     /* bit 2 = select palette bank 0 or 1 */
  79.     videobank = data;
  80. }
  81.  
  82. static WRITE_HANDLER( parodius_3fc0_w )
  83. {
  84.     if ((data & 0xf4) != 0x10) logerror("%04x: 3fc0 = %02x\n",cpu_get_pc(),data);
  85.  
  86.     /* bit 0/1 = coin counters */
  87.     coin_counter_w(0,data & 0x01);
  88.     coin_counter_w(1,data & 0x02);
  89.  
  90.     /* bit 3 = enable char ROM reading through the video RAM */
  91.     K052109_set_RMRD_line( ( data & 0x08 ) ? ASSERT_LINE : CLEAR_LINE );
  92.  
  93.     /* other bits unknown */
  94. }
  95.  
  96. static READ_HANDLER( parodius_sound_r )
  97. {
  98.     /* If the sound CPU is running, read the status, otherwise
  99.        just make it pass the test */
  100.     if (Machine->sample_rate != 0)     return K053260_r(2 + offset);
  101.     else return offset ? 0x00 : 0x80;
  102. }
  103.  
  104. static WRITE_HANDLER( parodius_sh_irqtrigger_w )
  105. {
  106.     cpu_cause_interrupt(1,0xff);
  107. }
  108.  
  109. static int nmi_enabled;
  110.  
  111. static void sound_nmi_callback( int param )
  112. {
  113.     cpu_set_nmi_line( 1, ( nmi_enabled ) ? CLEAR_LINE : ASSERT_LINE );
  114.  
  115.     nmi_enabled = 0;
  116. }
  117.  
  118. static void nmi_callback(int param)
  119. {
  120.     cpu_set_nmi_line(1,ASSERT_LINE);
  121. }
  122.  
  123. static WRITE_HANDLER( sound_arm_nmi_w )
  124. {
  125. //    sound_nmi_enabled = 1;
  126.     cpu_set_nmi_line(1,CLEAR_LINE);
  127.     timer_set(TIME_IN_USEC(50),0,nmi_callback);    /* kludge until the K053260 is emulated correctly */
  128. }
  129.  
  130. static READ_HANDLER( speedup_r )
  131. {
  132.     int data = memory_region(REGION_CPU1)[0x1837];
  133.  
  134.     if ( cpu_get_pc() == 0xa400 && data == 0 )
  135.         cpu_spinuntil_int();
  136.  
  137.     return data;
  138. }
  139.  
  140. /********************************************/
  141.  
  142. static struct MemoryReadAddress parodius_readmem[] =
  143. {
  144.     { 0x0000, 0x07ff, bankedram_r },
  145.     { 0x1837, 0x1837, speedup_r },
  146.     { 0x0800, 0x1fff, MRA_RAM },
  147.     { 0x3f8c, 0x3f8c, input_port_0_r },
  148.     { 0x3f8d, 0x3f8d, input_port_1_r },
  149.     { 0x3f8e, 0x3f8e, input_port_4_r },
  150.     { 0x3f8f, 0x3f8f, input_port_2_r },
  151.     { 0x3f90, 0x3f90, input_port_3_r },
  152.     { 0x3fa0, 0x3faf, K053244_r },
  153.     { 0x3fc0, 0x3fc0, watchdog_reset_r },
  154.     { 0x3fcc, 0x3fcd, parodius_sound_r },    /* K053260 */
  155.     { 0x2000, 0x27ff, parodius_052109_053245_r },
  156.     { 0x2000, 0x5fff, K052109_r },
  157.     { 0x6000, 0x9fff, MRA_BANK1 },            /* banked ROM */
  158.     { 0xa000, 0xffff, MRA_ROM },            /* ROM */
  159.     { -1 }    /* end of table */
  160. };
  161.  
  162. static struct MemoryWriteAddress parodius_writemem[] =
  163. {
  164.     { 0x0000, 0x07ff, bankedram_w, &ram },
  165.     { 0x0800, 0x1fff, MWA_RAM },
  166.     { 0x3fa0, 0x3faf, K053244_w },
  167.     { 0x3fb0, 0x3fbf, K053251_w },
  168.     { 0x3fc0, 0x3fc0, parodius_3fc0_w },
  169.     { 0x3fc4, 0x3fc4, parodius_videobank_w },
  170.     { 0x3fc8, 0x3fc8, parodius_sh_irqtrigger_w },
  171.     { 0x3fcc, 0x3fcd, K053260_w },
  172.     { 0x2000, 0x27ff, parodius_052109_053245_w },
  173.     { 0x2000, 0x5fff, K052109_w },
  174.     { 0x6000, 0x9fff, MWA_ROM },                    /* banked ROM */
  175.     { 0xa000, 0xffff, MWA_ROM },                    /* ROM */
  176.     { -1 }    /* end of table */
  177. };
  178.  
  179. static struct MemoryReadAddress parodius_readmem_sound[] =
  180. {
  181.     { 0x0000, 0xefff, MRA_ROM },
  182.     { 0xf000, 0xf7ff, MRA_RAM },
  183.     { 0xf801, 0xf801, YM2151_status_port_0_r },
  184.     { 0xfc00, 0xfc2f, K053260_r },
  185.     { -1 }    /* end of table */
  186. };
  187.  
  188. static struct MemoryWriteAddress parodius_writemem_sound[] =
  189. {
  190.     { 0x0000, 0xefff, MWA_ROM },
  191.     { 0xf000, 0xf7ff, MWA_RAM },
  192.     { 0xf800, 0xf800, YM2151_register_port_0_w },
  193.     { 0xf801, 0xf801, YM2151_data_port_0_w },
  194.     { 0xfa00, 0xfa00, sound_arm_nmi_w },
  195.     { 0xfc00, 0xfc2f, K053260_w },
  196.     { -1 }    /* end of table */
  197. };
  198.  
  199. /***************************************************************************
  200.  
  201.     Input Ports
  202.  
  203. ***************************************************************************/
  204.  
  205. INPUT_PORTS_START( parodius )
  206.     PORT_START    /* PLAYER 1 INPUTS */
  207.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
  208.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  209.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  210.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  211.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  212.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
  213.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  214.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  215.  
  216.     PORT_START    /* PLAYER 2 INPUTS */
  217.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START2 )
  218.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  219.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  220.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  221.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  222.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  223.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  224.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  225.  
  226.     PORT_START    /* DSW #1 */
  227.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )
  228.     PORT_DIPSETTING(    0x02, DEF_STR( 4C_1C ) )
  229.     PORT_DIPSETTING(    0x05, DEF_STR( 3C_1C ) )
  230.     PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
  231.     PORT_DIPSETTING(    0x04, DEF_STR( 3C_2C ) )
  232.     PORT_DIPSETTING(    0x01, DEF_STR( 4C_3C ) )
  233.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
  234.     PORT_DIPSETTING(    0x03, DEF_STR( 3C_4C ) )
  235.     PORT_DIPSETTING(    0x07, DEF_STR( 2C_3C ) )
  236.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )
  237.     PORT_DIPSETTING(    0x06, DEF_STR( 2C_5C ) )
  238.     PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )
  239.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
  240.     PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )
  241.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )
  242.     PORT_DIPSETTING(    0x09, DEF_STR( 1C_7C ) )
  243.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  244.     PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )
  245.     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
  246.     PORT_DIPSETTING(    0x50, DEF_STR( 3C_1C ) )
  247.     PORT_DIPSETTING(    0x80, DEF_STR( 2C_1C ) )
  248.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_2C ) )
  249.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_3C ) )
  250.     PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )
  251.     PORT_DIPSETTING(    0x30, DEF_STR( 3C_4C ) )
  252.     PORT_DIPSETTING(    0x70, DEF_STR( 2C_3C ) )
  253.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )
  254.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_5C ) )
  255.     PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )
  256.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
  257.     PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )
  258.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ) )
  259.     PORT_DIPSETTING(    0x90, DEF_STR( 1C_7C ) )
  260. //    PORT_DIPSETTING(    0x00, "No Use" )
  261.  
  262.     PORT_START    /* DSW #2 */
  263.     PORT_DIPNAME( 0x03, 0x02, DEF_STR( Lives ) )
  264.     PORT_DIPSETTING(    0x03, "2" )
  265.     PORT_DIPSETTING(    0x02, "3" )
  266.     PORT_DIPSETTING(    0x01, "4" )
  267.     PORT_DIPSETTING(    0x00, "7" )
  268.     PORT_DIPNAME( 0x04, 0x00, DEF_STR( Cabinet ) )
  269.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  270.     PORT_DIPSETTING(    0x04, DEF_STR( Cocktail ) )
  271.     PORT_DIPNAME( 0x18, 0x18, DEF_STR( Bonus_Life ) )
  272.     PORT_DIPSETTING(    0x18, "20000 80000" )
  273.     PORT_DIPSETTING(    0x10, "30000 100000" )
  274.     PORT_DIPSETTING(    0x08, "20000" )
  275.     PORT_DIPSETTING(    0x00, "70000" )
  276.     PORT_DIPNAME( 0x60, 0x40, DEF_STR( Difficulty ) )
  277.     PORT_DIPSETTING(    0x60, "Easy" )
  278.     PORT_DIPSETTING(    0x40, "Normal" )
  279.     PORT_DIPSETTING(    0x20, "Difficult" )
  280.     PORT_DIPSETTING(    0x00, "Very Difficult" )
  281.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) )
  282.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  283.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  284.  
  285.     PORT_START    /* DSW #3 */
  286.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN3 )
  287.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE )
  288.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN1 )
  289.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN2 )
  290.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Flip_Screen ) )
  291.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  292.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  293.     PORT_DIPNAME( 0x20, 0x20, "Upright Controls" )
  294.     PORT_DIPSETTING(    0x20, "Single" )
  295.     PORT_DIPSETTING(    0x00, "Dual" )
  296.     PORT_SERVICE( 0x40, IP_ACTIVE_LOW )
  297.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
  298.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  299.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  300. INPUT_PORTS_END
  301.  
  302.  
  303.  
  304. /***************************************************************************
  305.  
  306.     Machine Driver
  307.  
  308. ***************************************************************************/
  309.  
  310. static struct YM2151interface ym2151_interface =
  311. {
  312.     1,            /* 1 chip */
  313.     3579545,    /* 3.579545 MHz */
  314.     { YM3012_VOL(100,MIXER_PAN_LEFT,100,MIXER_PAN_RIGHT) },
  315.     { 0 },
  316. };
  317.  
  318. static struct K053260_interface k053260_interface =
  319. {
  320.     3579545,
  321.     REGION_SOUND1, /* memory region */
  322.     { MIXER(70,MIXER_PAN_LEFT), MIXER(70,MIXER_PAN_RIGHT) },
  323. //    sound_nmi_callback
  324. };
  325.  
  326.  
  327.  
  328. static struct MachineDriver machine_driver_parodius =
  329. {
  330.     /* basic machine hardware */
  331.     {
  332.         {
  333.             CPU_KONAMI,        /* 053248 */
  334.             3000000,        /* ? */
  335.             parodius_readmem,parodius_writemem,0,0,
  336.             parodius_interrupt,1
  337.         },
  338.         {
  339.             CPU_Z80 | CPU_AUDIO_CPU,
  340.             3579545,
  341.             parodius_readmem_sound, parodius_writemem_sound,0,0,
  342.             ignore_interrupt,0    /* IRQs are triggered by the main CPU */
  343.                                 /* NMIs are triggered by the 053260 */
  344.         }
  345.     },
  346.     60, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  347.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  348.     parodius_init_machine,
  349.  
  350.     /* video hardware */
  351.     64*8, 32*8, { 14*8, (64-14)*8-1, 2*8, 30*8-1 },
  352.     0,    /* gfx decoded by konamiic.c */
  353.     2048, 2048,
  354.     0,
  355.  
  356.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  357.     0,
  358.     parodius_vh_start,
  359.     parodius_vh_stop,
  360.     parodius_vh_screenrefresh,
  361.  
  362.     /* sound hardware */
  363.     SOUND_SUPPORTS_STEREO,0,0,0,
  364.     {
  365.         {
  366.             SOUND_YM2151,
  367.             &ym2151_interface
  368.         },
  369.         {
  370.             SOUND_K053260,
  371.             &k053260_interface
  372.         }
  373.     }
  374. };
  375.  
  376. /***************************************************************************
  377.  
  378.   Game ROMs
  379.  
  380. ***************************************************************************/
  381.  
  382. ROM_START( parodius )
  383.     ROM_REGION( 0x51000, REGION_CPU1 ) /* code + banked roms + palette RAM */
  384.     ROM_LOAD( "955e01.bin", 0x10000, 0x20000, 0x49baa334 )
  385.     ROM_LOAD( "955e02.bin", 0x30000, 0x18000, 0x14010d6f )
  386.     ROM_CONTINUE(           0x08000, 0x08000 )
  387.  
  388.     ROM_REGION( 0x10000, REGION_CPU2 ) /* 64k for the sound CPU */
  389.     ROM_LOAD( "955e03.bin", 0x0000, 0x10000, 0x940aa356 )
  390.  
  391.     ROM_REGION( 0x100000, REGION_GFX1 ) /* graphics ( don't dispose as the program can read them ) */
  392.     ROM_LOAD( "955d07.bin", 0x000000, 0x080000, 0x89473fec ) /* characters */
  393.     ROM_LOAD( "955d08.bin", 0x080000, 0x080000, 0x43d5cda1 ) /* characters */
  394.  
  395.     ROM_REGION( 0x100000, REGION_GFX2 ) /* graphics ( don't dispose as the program can read them ) */
  396.     ROM_LOAD( "955d05.bin", 0x000000, 0x080000, 0x7a1e55e0 )    /* sprites */
  397.     ROM_LOAD( "955d06.bin", 0x080000, 0x080000, 0xf4252875 )    /* sprites */
  398.  
  399.     ROM_REGION( 0x80000, REGION_SOUND1 ) /* 053260 samples */
  400.     ROM_LOAD( "955d04.bin", 0x00000, 0x80000, 0xe671491a )
  401. ROM_END
  402.  
  403. /***************************************************************************
  404.  
  405.   Game driver(s)
  406.  
  407. ***************************************************************************/
  408.  
  409. static void parodius_banking(int lines)
  410. {
  411.     unsigned char *RAM = memory_region(REGION_CPU1);
  412.     int offs = 0;
  413.  
  414.     if (lines & 0xf0) logerror("%04x: setlines %02x\n",cpu_get_pc(),lines);
  415.  
  416.     offs = 0x10000 + (((lines & 0x0f)^0x0f) * 0x4000);
  417.     if (offs >= 0x48000) offs -= 0x40000;
  418.     cpu_setbank( 1, &RAM[offs] );
  419. }
  420.  
  421. static void parodius_init_machine( void )
  422. {
  423.     unsigned char *RAM = memory_region(REGION_CPU1);
  424.  
  425.     konami_cpu_setlines_callback = parodius_banking;
  426.  
  427.     paletteram = &memory_region(REGION_CPU1)[0x48000];
  428.  
  429.     videobank = 0;
  430.  
  431.     /* init the default bank */
  432.     cpu_setbank(1,&RAM[0x10000]);
  433. }
  434.  
  435.  
  436. static void init_parodius(void)
  437. {
  438.     konami_rom_deinterleave_2(REGION_GFX1);
  439.     konami_rom_deinterleave_2(REGION_GFX2);
  440. }
  441.  
  442.  
  443.  
  444. GAME( 1990, parodius, 0, parodius, parodius, parodius, ROT0, "Konami", "Parodius DA! (Japan)" )
  445.